<template>
  <div>
    <el-form :model="dataForm" :rules="dataRule" ref="dataForm" @keyup.enter.native="dataFormSubmit()" label-width="80px">
      <el-form-item prop="chargingMinutes" label-width="0">
        宾客进店
        <el-input style="width: 100px;" v-model="dataForm.chargingMinutes" placeholder=""></el-input>
        分钟开始计费
      </el-form-item>

      <el-form-item prop="afterPointNext" label-width="0">
        1、进店时间在
        <el-time-select
          style="width: 110px;"
          placeholder="时间"
          v-model="dataForm.afterPointNext"
          :picker-options="{
            start: '00:00',
            step: '00:01',
            end: '23:59'
          }"
        ></el-time-select>
        之后的，算第二天退房（例如，如果是6点，那么当天6点之后开的房间就是第二天中午退房，0点到6点开房就是当天中午退房）。
      </el-form-item>

      <el-form-item prop="exitPoint" label-width="0">
        2、全天房中午退房时间
        <el-time-select
          style="width: 110px;"
          placeholder="时间"
          v-model="dataForm.exitPoint"
          :picker-options="{
            start: '00:00',
            step: '00:01',
            end: '23:59'
          }"
        ></el-time-select>
        ，超时则
        <el-select v-model="dataForm.exceedType" style="width: 150px;"  placeholder="请选择">
          <el-option v-for="item in options" :key="item.value" :label="item.label" :value="item.value"></el-option>
        </el-select>
        ，直到
        <el-time-select
          style="width: 110px;"
          placeholder="时间"
          v-model="dataForm.nextTime"
          :picker-options="{
            start: '00:00',
            step: '00:01',
            end: '23:59'
          }"
        ></el-time-select>
        ，加收全天房费。
      </el-form-item>

      <el-form-item prop="exceedMinutes" label-width="0" v-if="dataForm.exceedType == 0">
        3、超时之后，每隔
        <el-input style="width: 100px;" v-model="dataForm.exceedMinutes" placeholder=""></el-input>
        分钟收取
        <el-input style="width: 100px;" v-model="dataForm.exceedMoney" placeholder=""></el-input>
        元，不足
        <el-input style="width: 100px;" v-model="dataForm.exceedMinutes" placeholder=""></el-input>
        分钟，超过
        <el-input style="width: 100px;" v-model="dataForm.insufficientMinutes" placeholder=""></el-input>
        分钟加收
        <el-input style="width: 100px;" v-model="dataForm.insufficientMoney" placeholder=""></el-input>
      </el-form-item>

      <el-form-item prop="timeoutGraceMinutes" label-width="0">
        全天房超过退房时间可以再宽限
        <el-input style="width: 100px;" v-model="dataForm.timeoutGraceMinutes" placeholder=""></el-input>
        分钟
      </el-form-item>
    </el-form>
    <span slot="footer" class="dialog-footer">
      <el-button @click="init">刷新</el-button>
      <el-button type="primary" @click="dataFormSubmit()">{{ $t('Common.Confirm') }}</el-button>
    </span>
  </div>
</template>

<script>
export default {
  data() {
    return {
      options: [
        {
          value: 0,
          label: '按分钟加收'
        },
        {
          value: 1,
          label: '按半天房费加收'
        },
        {
          value: 2,
          label: '不收加房费'
        }
      ],
      visible: false,
      dataForm: {
        id: 0,
        sellerId: '',
        createTime: '',
        updateTime: '',
        chargingMinutes: '',
        afterPointNext: '',
        exitPoint: '',
        exceedType: '',
        nextTime: '',
        exceedMinutes: '',
        exceedMoney: '',
        insufficientMinutes: '',
        insufficientMoney: '',
        timeoutGraceMinutes: ''
      },
      dataRule: {
        sellerId: [{ required: true, message: '商家不能为空', trigger: 'blur' }],
        createTime: [{ required: true, message: '创建时间不能为空', trigger: 'blur' }],
        updateTime: [{ required: true, message: '更新时间不能为空', trigger: 'blur' }],
        chargingMinutes: [{ required: true, message: '宾客进店计费分钟不能为空', trigger: 'blur' }],
        afterPointNext: [{ required: true, message: '进店时间在多少分钟之后的，算第二天退房不能为空', trigger: 'blur' }],
        exitPoint: [{ required: true, message: '退房时间不能为空', trigger: 'blur' }],
        exceedType: [{ required: true, message: '超出时间计费规则(0按分钟1加收半天2不收房费)不能为空', trigger: 'blur' }],
        nextTime: [{ required: true, message: '直到多少分钟加收全天房费不能为空', trigger: 'blur' }],
        exceedMinutes: [{ required: true, message: '超时后按多少分钟计费不能为空', trigger: 'blur' }],
        exceedMoney: [{ required: true, message: '上个字段收取多少元不能为空', trigger: 'blur' }],
        insufficientMinutes: [{ required: true, message: '不足按多少分钟超过多少分钟计费不能为空', trigger: 'blur' }],
        insufficientMoney: [{ required: true, message: '上个字段加收不能为空', trigger: 'blur' }],
        timeoutGraceMinutes: [{ required: true, message: '超时宽限多少分钟不能为空', trigger: 'blur' }]
      }
    };
  },
  activated() {
    this.init();
  },
  methods: {
    init() {
      this.visible = true;
      this.$nextTick(() => {
        this.$refs['dataForm'].resetFields();
        this.$http({
          url: this.$http.adornUrl(`/hotel/thotelfloorroomdayrule/seller`),
          method: 'get',
          params: this.$http.adornParams()
        }).then(({ data }) => {
          if (data && data.code === 0) {
            this.dataForm.id = data.tHotelFloorRoomDayRule.id;
            this.dataForm.sellerId = data.tHotelFloorRoomDayRule.sellerId;
            this.dataForm.createTime = data.tHotelFloorRoomDayRule.createTime;
            this.dataForm.updateTime = data.tHotelFloorRoomDayRule.updateTime;
            this.dataForm.chargingMinutes = data.tHotelFloorRoomDayRule.chargingMinutes;
            this.dataForm.afterPointNext = data.tHotelFloorRoomDayRule.afterPointNext;
            this.dataForm.exitPoint = data.tHotelFloorRoomDayRule.exitPoint;
            this.dataForm.exceedType = data.tHotelFloorRoomDayRule.exceedType;
            this.dataForm.nextTime = data.tHotelFloorRoomDayRule.nextTime;
            this.dataForm.exceedMinutes = data.tHotelFloorRoomDayRule.exceedMinutes;
            this.dataForm.exceedMoney = data.tHotelFloorRoomDayRule.exceedMoney;
            this.dataForm.insufficientMinutes = data.tHotelFloorRoomDayRule.insufficientMinutes;
            this.dataForm.insufficientMoney = data.tHotelFloorRoomDayRule.insufficientMoney;
            this.dataForm.timeoutGraceMinutes = data.tHotelFloorRoomDayRule.timeoutGraceMinutes;
          }
        });
      });
    },
    // 表单提交
    dataFormSubmit() {
         
      var lists=this.options.filter(item => item.value==this.dataForm.exceedType)
      this.$refs['dataForm'].validate(valid => {
        if (valid) {
          this.$http({
            url: this.$http.adornUrl(`/hotel/thotelfloorroomdayrule/update`),
            method: 'post',
            data: this.$http.adornData({
              id: this.dataForm.id,
              sellerId: this.dataForm.sellerId,
              createTime: this.dataForm.createTime,
              updateTime: this.dataForm.updateTime,
              chargingMinutes: this.dataForm.chargingMinutes,
              afterPointNext: this.dataForm.afterPointNext,
              exitPoint: this.dataForm.exitPoint,
              exceedType: this.dataForm.exceedType,
              nextTime: this.dataForm.nextTime,
              exceedMinutes: this.dataForm.exceedMinutes,
              exceedMoney: this.dataForm.exceedMoney,
              insufficientMinutes: this.dataForm.insufficientMinutes,
              insufficientMoney: this.dataForm.insufficientMoney,
              timeoutGraceMinutes: this.dataForm.timeoutGraceMinutes,
              type:lists[0].label
            })
          }).then(({ data }) => {
            if (data && data.code === 0) {
              this.$message({
                message: this.$t('Common.OperationSuccessful'),
                type: 'success',
                duration: 1500
              });
            } else {
              this.$message.error(data.msg);
            }
          });
        }
      });
    }
  }
};
</script>
